//
//  functions.m
//  yilutongxing
//
//  Created by T&J on 2017/6/9.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "functions.h"
#import "CommonDefine.h"

@implementation functions

+ (CGFloat)UIEdgeInsetsGetHorizontalValue:(UIEdgeInsets) insets {
    return insets.left + insets.right;
}

+ (CGFloat)UIEdgeInsetsGetVerticalValue:(UIEdgeInsets) insets {
    return insets.top + insets.bottom;
}

+ (BOOL)ishaveGZJQLitteral:(NSString *)str{
    NSRange rg = [str rangeOfString:@"广州军区"];
    return !(rg.location==NSNotFound);
}

+ (NSMutableArray*)sortHospitalByGZ:(NSArray *)hospital_arr{
    NSMutableArray *new_arr = [NSMutableArray array];
    NSEnumerator *en = [hospital_arr objectEnumerator];
    id o = nil;
    while (o = [en nextObject]) {
        NSString *name = [o valueForKey:@"name"];
        if([name isEqualToString:@"广州军区广州总医院"]){
            if (new_arr.count==0) {
                [new_arr insertObject:o atIndex:0];
            }
            else {
                id ho = new_arr[0];
                NSString *tname = [ho valueForKey:@"name"];
                if (![tname isEqualToString:@"广州军区广州总医院"]){
                    [new_arr insertObject:o atIndex:0];
                }
            }
        }
        else if ([functions ishaveGZJQLitteral:name]) {
            if (new_arr.count==0) {
                [new_arr addObject:o];
            }
            else {
                [new_arr insertObject:o atIndex:1];
            }
        }
        else {
            [new_arr addObject:o];
        }
    }
    return new_arr;
}

+ (void)dianalTelephone:(NSString *)telnum{
    if (iOS10Later) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", telnum]] options:@{} completionHandler:nil];
    }
    else {
        UIWebView * callWebview = [[UIWebView alloc]init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", telnum]]]];
        [[UIApplication sharedApplication].keyWindow addSubview:callWebview];
    }
}

@end

